/**
 * Created by zhang on 4/28/2017.
 */
var http = require('http');

var options = {
    hostname: '127.0.0.1',
    port: 8000,
    path: '/',
    method: 'GET',
    header: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
};

/**
 * HTTP request
 */
http.request(options, function (response) {

    console.log(response.headers);

    var body = [];

    response.on('data', function (chunk) {
        body.push(chunk);
    });

    response.on('end', function () {
        body = Buffer.concat(body);
        console.log(body.toString());
    })

}).end();

/**
 * convenient GET request
 */
http.get('http://127.0.0.1:8000', function (response) {
    console.log(response.headers);
})